package com.cjkj.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cjkj.common.annotation.Log;
import com.cjkj.common.core.controller.BaseController;
import com.cjkj.common.core.domain.AjaxResult;
import com.cjkj.common.enums.BusinessType;
import com.cjkj.purchase.domain.PurchaseOutboundRecord;
import com.cjkj.purchase.service.IPurchaseOutboundRecordService;
import com.cjkj.common.utils.poi.ExcelUtil;
import com.cjkj.common.core.page.TableDataInfo;

/**
 * 采购材料出库记录Controller
 * 
 * @author cjkj
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/purchase/out/record")
public class PurchaseOutboundRecordController extends BaseController
{
    @Resource
    private IPurchaseOutboundRecordService purchaseOutboundRecordService;

    /**
     * 查询采购材料出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseOutboundRecord purchaseOutboundRecord)
    {
        startPage();
        List<PurchaseOutboundRecord> list = purchaseOutboundRecordService.selectPurchaseOutboundRecordList(purchaseOutboundRecord);
        return getDataTable(list);
    }

    /**
     * 导出采购材料出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "采购材料出库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseOutboundRecord purchaseOutboundRecord)
    {
        List<PurchaseOutboundRecord> list = purchaseOutboundRecordService.selectPurchaseOutboundRecordList(purchaseOutboundRecord);
        ExcelUtil<PurchaseOutboundRecord> util = new ExcelUtil<PurchaseOutboundRecord>(PurchaseOutboundRecord.class);
        util.exportExcel(response, list, "采购材料出库记录数据");
    }

    /**
     * 获取采购材料出库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(purchaseOutboundRecordService.selectPurchaseOutboundRecordByRecordId(recordId));
    }

    /**
     * 新增采购材料出库记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "采购材料出库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseOutboundRecord purchaseOutboundRecord)
    {
        return toAjax(purchaseOutboundRecordService.insertPurchaseOutboundRecord(purchaseOutboundRecord));
    }

    /**
     * 修改采购材料出库记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "采购材料出库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseOutboundRecord purchaseOutboundRecord)
    {
        return toAjax(purchaseOutboundRecordService.updatePurchaseOutboundRecord(purchaseOutboundRecord));
    }

    /**
     * 删除采购材料出库记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "采购材料出库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(purchaseOutboundRecordService.deletePurchaseOutboundRecordByRecordIds(recordIds));
    }
}
